//
//  SZLBasicViewController.m
//  Shengzhuli
//
//  Created by 卡忙科技 on 16/7/18.
//  Copyright © 2016年 kamangkeji. All rights reserved.
//

#import "SZLBasicViewController.h"
#import "WaterRippleWait.h"
#import "MBProgressHUD+MJ.h"
#import "GGIndicatorHud.h"
#import "LottieLoading.h"

@interface SZLBasicViewController ()

@property (nonatomic,assign) SEL sel;//重新加载的方法
@property (nonatomic,strong) UIView *coverView;

@end

@implementation SZLBasicViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
}

- (void)createNaviNeedsBack:(BOOL)need
{
    _naviBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, 64)];
    _naviBar.backgroundColor = WineColor;
    [self.view addSubview:_naviBar];
    if (need) {
        UIButton *backBtn = [[UIButton alloc]init];
        backBtn.x = 10;
        backBtn.y = 28;
        [backBtn setBackgroundImage:[UIImage imageNamed:@"btn_back_normal"] forState:UIControlStateNormal];
        [backBtn setBackgroundImage:[UIImage imageNamed:@"btn_back_pressed"] forState:UIControlStateHighlighted];
        [backBtn addTarget:self action:@selector(pop) forControlEvents:UIControlEventTouchUpInside];
        [backBtn sizeToFit];
        [_naviBar addSubview:backBtn];
    }
}
- (void)pop
{
    if (self.navigationController) {
        [self.navigationController popViewControllerAnimated:YES];
    }else{
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}
#pragma mark ----------------请求失败相关---------------
- (void)showRequestAgainView:(SEL)action
{
    [self.view addSubview:self.refreshBtn];
    self.sel = action;
}
- (void)hideRequestAgainView
{
    if (self.refreshBtn.superview) {
        [self.refreshBtn removeFromSuperview];
    }
}
- (void)refreshClick
{
    [self performSelector:self.sel withObject:nil afterDelay:0.0];
}

- (void)showReloadViewWithTarget:(id)target action:(SEL)action
{
    [self.view addSubview:self.showView];
    [self.showView addTarget:self action:action];
}
- (void)hideReloadView
{
    [self.showView removeFromSuperview];
}
#pragma mark ----------------暂无数据--------------------------
- (void)showNoDataView:(CGRect)frame
{
    [self showNoDataView:frame title:nil];
}
- (void)showNoDataView:(CGRect)frame title:(NSString *)tips;
{
    self.noDataView.frame = frame;
    self.noDataView.tips = tips;
    [self.view addSubview:self.noDataView];
}
- (void)showNoDataView:(UIView *)view frame:(CGRect)frame title:(NSString *)tips
{
    self.noDataView.frame = frame;
    self.noDataView.tips = tips;
    [view addSubview:self.noDataView];
}
- (void)hideNoDataView
{
    if (self.noDataView.superview) {
        [self.noDataView removeFromSuperview];
    }
}
#pragma -------------------noDataLab-------------------
- (void)showNoDataLab:(UIView *)view range:(CGRect)frame title:(NSString *)tips;
{
    self.noDataLab.text = tips;
    self.noDataLab.size = [self.noDataLab sizeThatFits:CGSizeMake(frame.size.width, frame.size.height)];
    self.noDataLab.center = CGPointMake(frame.size.width*0.5, frame.origin.y+frame.size.height*0.5);
    [view addSubview:self.noDataLab];
}
- (void)hideNoDataLab
{
    if (self.noDataLab.superview) {
        [self.noDataLab removeFromSuperview];
    }
}
#pragma mark --------------------指示器相关------------------
- (void)showWaiter
{
//    [WaterRippleWait waterRippleShowInView:self.view];
    [LottieLoading showLoadingInView:self.view];
}
- (void)showClearBgWaiter
{
//    [WaterRippleWait waterRippleShowInView:self.view backgroundColor:[UIColor clearColor]];
    [LottieLoading showLoadingInView:self.view];
}
- (void)hideWaiter
{
//    [WaterRippleWait hideWaterRippleInView:self.view];
    [LottieLoading hideLoadingInView:self.view];
}
#pragma mark -----------------------------------------------
- (void)showOnlyText:(NSString *)text
{
    [MBProgressHUD showOnlyText:text view:self.view];
}

- (UIButton *)refreshBtn
{
    if (!_refreshBtn) {
        _refreshBtn = [[UIButton alloc]init];
        [_refreshBtn setImage:GetImage(@"refresh") forState:UIControlStateNormal];
        [_refreshBtn setAdjustsImageWhenHighlighted:NO];
        [_refreshBtn setTitle:@"点击重新加载" forState:UIControlStateNormal];
        [_refreshBtn setTitleColor:RGBColorA(0, 0, 0, 0.6) forState:UIControlStateNormal];
        [_refreshBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
        [_refreshBtn addTarget:self action:@selector(refreshClick) forControlEvents:UIControlEventTouchUpInside];
        _refreshBtn.titleLabel.font = Font(14);
        [_refreshBtn sizeToFit];
        _refreshBtn.center = CGPointMake(ScreenW*0.5, ScreenH*0.45);
    }
    return _refreshBtn;
}

- (UILabel *)titleLab
{
    if (!_titleLab) {
        _titleLab = [[UILabel alloc]initWithFrame:CGRectMake((ScreenW-100)/2.0, 20+12, 100, 20)];
        _titleLab.textColor = [UIColor whiteColor];
        _titleLab.font = Font(20);
        _titleLab.textAlignment = NSTextAlignmentCenter;
        [_naviBar addSubview:_titleLab];
    }
    return _titleLab;
}
- (UILabel *)noDataLab
{
    if (!_noDataLab) {
        _noDataLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, ScreenW, 20)];
        _noDataLab.font = Font(16);
        _noDataLab.numberOfLines = 0;
        _noDataLab.backgroundColor = [UIColor clearColor];
        _noDataLab.textColor = [UIColor grayColor];
    }
    return _noDataLab;
}
- (NoDataView *)noDataView
{
    if (!_noDataView) {
        _noDataView = [[NoDataView alloc]init];
    }
    return _noDataView;
}
- (NoDataShowView *)showView
{
    if (!_showView) {
        _showView = [NoDataShowView noDataView];
        _showView.frame = self.view.bounds;
    }
    return _showView;
}

@end
